package com.ycMc.utils;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

public class StringUtils {

    private static final Pattern phonePattern = Pattern.compile("^((1[0-9]))\\d{9}$");
    ;

    public static boolean isEmpty(String input) {
        return org.springframework.util.StringUtils.isEmpty(input);
    }

    public static boolean isValidPhone(String phone) {
        if (isEmpty(phone) || !phonePattern.matcher(phone).matches()) {
            return false;
        }
        return true;
    }

    public static boolean isValidImei(String imei) {
        if (isEmpty(imei) || imei.length() < 5) {
            return false;
        }
        return true;
    }

    public static String listToString(List<String> stringList) {
        if (stringList == null) {
            return null;
        }
        StringBuilder result = new StringBuilder();
        boolean flag = false;
        for (String string : stringList) {
            if (flag) {
                result.append(",");
            } else {
                flag = true;
            }

            result.append(string);
        }
        return result.toString();
    }

    /**
     * 将逗号分隔的字符串转换为List
     *
     * @param str
     * @return
     */
    public static List<String> String2List(String str) {
        if ( StringUtils.isEmpty(str)) {
            return null;
        }
        String[] split = str.split(",");
        List<String> strList = Arrays.asList(split);
        return strList;
    }
}
